package com.wsjj.yjh.controller;

import com.wsjj.yjh.MianshiApplication;
import com.wsjj.yjh.bean.*;
import com.wsjj.yjh.server.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.annotation.Resource;
import java.awt.datatransfer.StringSelection;
import java.util.HashMap;
import java.util.Map;


@Controller
public class UseController {

    @Autowired
    LinuxShellTableServer linuxShellTableServer;
    @Autowired
    HadoopTableServer hadoopTableServer;
    @Autowired
    ZookeeperTableServer zookeeperTableServer;
    @Autowired
    KafkaTableServer kafkaTableServer;
    @Autowired
    FlumeDataxMaxwellSqoopFlinkCDCTableServer flumeDataxMaxwellSqoopFlinkCDCTableServer;
    @Autowired
    HiveTableServer hiveTableServer;
    @Resource
    SparkTableServer sparkTableServer;
    @Resource
    FlinkTableServer flinkTableServer;
    @Resource
    HbaseClickhouseDorisDSTableServer hbaseClickhouseDorisDSTableServer;
    @Resource
    JavaMysqlRedisJvmDockerTableServer javaMysqlRedisJvmDockerTableServer;
    @Resource
    OfflineTableServer offlineTableServer;
    @Resource
    RealtimeTableServer realtimeTableServer;


    HashMap<String, String> stringStringHashMap =null;
    StringBuffer stringBuffer = null;


    @PostMapping("/use/login")
    public String Use( Model model,@RequestParam("selectOption") String selectOption){
        stringBuffer = new StringBuffer();
        stringBuffer.append(selectOption);

        stringStringHashMap = new HashMap<>();


        System.out.println(selectOption);

        ifKuJia(selectOption,model);



        return "use.html";
    }


    @PostMapping("/use/Problem")
    public String Problem( Model model){

        for (String key:stringStringHashMap.keySet()){
            String value = stringStringHashMap.get(key);
            model.addAttribute("key",key);
            model.addAttribute("value",value);

        }
        return "use2.html";

    }

    @PostMapping("/use/Result")
    public String Result( Model model){


        String selectOption = stringBuffer.toString();
        System.out.println(selectOption);
        ifKuJia(selectOption,model);

        return "use.html";

    }

    public void ifKuJia(String selectOption,Model model){
        switch (selectOption){
            case "linux+shell":
                LinuxShellTable linuxShellTable = linuxShellTableServer.selectById();
                model.addAttribute("message",linuxShellTable.getProblem());
                stringStringHashMap.clear();
                System.out.println(linuxShellTable.getProblem());
                stringStringHashMap.put(linuxShellTable.getProblem(),linuxShellTable.getResult());
                break;
            case "hadoop":
                HadoopTable hadoopTable = hadoopTableServer.selectById();
                model.addAttribute("message",hadoopTable.getProblem());
                stringStringHashMap.clear();
                System.out.println(hadoopTable.getProblem());
                stringStringHashMap.put(hadoopTable.getProblem(),hadoopTable.getResult());
                break;
            case "zookeeper":
                ZookeeperTable zookeeperTable = zookeeperTableServer.selectById();
                model.addAttribute("message",zookeeperTable.getProblem());
                stringStringHashMap.clear();
                System.out.println(zookeeperTable.getProblem());
                stringStringHashMap.put(zookeeperTable.getProblem(),zookeeperTable.getResult());
                break;
            case "kafka":
                KafkaTable kafkaTable = kafkaTableServer.selectById();
                model.addAttribute("message",kafkaTable.getProblem());
                stringStringHashMap.clear();
                System.out.println(kafkaTable.getProblem());
                stringStringHashMap.put(kafkaTable.getProblem(),kafkaTable.getResult());
                break;
            case "gather":
                FlumeDataxMaxwellSqoopFlinkCDCTable flumeDataxMaxwellSqoopFlinkCDCTable = flumeDataxMaxwellSqoopFlinkCDCTableServer.selectById();
                model.addAttribute("message",flumeDataxMaxwellSqoopFlinkCDCTable.getProblem());
                stringStringHashMap.clear();
                System.out.println(flumeDataxMaxwellSqoopFlinkCDCTable.getProblem());
                stringStringHashMap.put(flumeDataxMaxwellSqoopFlinkCDCTable.getProblem(),flumeDataxMaxwellSqoopFlinkCDCTable.getResult());
                break;
            case "hive":
                HiveTable hiveTable = hiveTableServer.selectById();
                model.addAttribute("message",hiveTable.getProblem());
                stringStringHashMap.clear();
                System.out.println(hiveTable.getProblem());
                stringStringHashMap.put(hiveTable.getProblem(),hiveTable.getResult());
                break;
            case "spark":
                SparkTable sparkTable = sparkTableServer.selectById();
                model.addAttribute("message",sparkTable.getProblem());
                stringStringHashMap.clear();
                System.out.println(sparkTable.getProblem());
                stringStringHashMap.put(sparkTable.getProblem(),sparkTable.getResult());
                break;
            case "flink":
                FlinkTable flinkTable = flinkTableServer.selectById();
                model.addAttribute("message",flinkTable.getProblem());
                stringStringHashMap.clear();
                System.out.println(flinkTable.getProblem());
                stringStringHashMap.put(flinkTable.getProblem(),flinkTable.getResult());
                break;
            case "olaptable":
                HbaseClinkhouseDorisDSTable hbaseClinkhouseDorisDSTable = hbaseClickhouseDorisDSTableServer.selectById();
                model.addAttribute("message",hbaseClinkhouseDorisDSTable.getProblem());
                stringStringHashMap.clear();
                System.out.println(hbaseClinkhouseDorisDSTable.getProblem());
                stringStringHashMap.put(hbaseClinkhouseDorisDSTable.getProblem(),hbaseClinkhouseDorisDSTable.getResult());
                break;
            case "java":
                JavaMysqlRedisJvmDockerTable javaMysqlRedisJvmDockerTable = javaMysqlRedisJvmDockerTableServer.selectById();
                model.addAttribute("message",javaMysqlRedisJvmDockerTable.getProblem());
                stringStringHashMap.clear();
                System.out.println(javaMysqlRedisJvmDockerTable.getProblem());
                stringStringHashMap.put(javaMysqlRedisJvmDockerTable.getProblem(),javaMysqlRedisJvmDockerTable.getResult());
                break;
            case "offline":
                OfflineTable offlineTable = offlineTableServer.selectById();
                model.addAttribute("message",offlineTable.getProblem());
                stringStringHashMap.clear();
                System.out.println(offlineTable.getProblem());
                stringStringHashMap.put(offlineTable.getProblem(),offlineTable.getResult());
                break;
            case "realtime":
                RealtimeTable realtimeTable = realtimeTableServer.selectById();
                model.addAttribute("message",realtimeTable.getProblem());
                stringStringHashMap.clear();
                System.out.println(realtimeTable.getProblem());
                stringStringHashMap.put(realtimeTable.getProblem(),realtimeTable.getResult());
                break;
        }

    }


}
